package com.nowcoder.community.event;
import com.alibaba.fastjson.JSONObject;
import com.nowcoder.community.entity.Event;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
public class EventProducer {
    @Resource
    private KafkaTemplate kafkaTemplate;
    private static final Logger logger = LoggerFactory.getLogger(EventConsumer.class);
    // 处理事件
    public void fireEvent(Event event) {
        // 将事件发布到指定的主题
        kafkaTemplate.send(event.getTopic(), JSONObject.toJSONString(event));
        logger.info(JSONObject.toJSONString(event));
        logger.info("生产成功："+event.getTopic());
        
    }
}